package es.pawer.android.listacompras.data;

/**
 * This class represents the goods you can buy in any shop. Any good has name or
 * description, a sum of orderPoints and, optionally, a price and the currency.
 * 
 * @author plozano
 * @version 1.0
 * 
 */
public class ItemTO implements ITransferObject {

	private static final long serialVersionUID = -488809214317093099L;

	private int id;
	private String name;
	private int orderPoints;
	private int price;
	private int units;
	private Long listId;

	/**
	 * Constructor with name
	 * 
	 * @param n
	 */
	public ItemTO(String n) {
		this.name = n;
		orderPoints = 0;
		price = 0;
	}

	/**
	 * Empty constructor (JavaBean)
	 */
	public ItemTO() {
	}

	public Long getListId() {
		return listId;
	}

	public void setListId(Long listID) {
		this.listId = listID;
	}

	public int getUnits() {
		return units;
	}

	public void setUnits(int units) {
		this.units = units;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getOrderPoints() {
		return orderPoints;
	}

	public void setOrderPoints(int orderPoints) {
		this.orderPoints = orderPoints;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int value) {
		this.price = value;
	}

	public void addOrderPoints(int i) {
		this.orderPoints += i;
	}

	/**
	 * In order to sort the elements, the attribute orderPoints is compared.
	 */
	public int compareTo(ITransferObject g) {
		if (g != null && g instanceof ItemTO) {
			ItemTO good = (ItemTO) g;
			if (this.orderPoints>good.orderPoints) {
				return -1;
			} else if (this.orderPoints==good.orderPoints) {
				return 0;
			}
		}
		return 1;
	}
	@Override
	public String toString() {
		String result = this.getName() + " " + this.getUnits() + " unit";
		if (this.getUnits() > 1) {
			result += "s";
		}
		return result;
	}
	
	@Override
	public ItemTO clone() {
		ItemTO it=new ItemTO(this.getName());
		it.setListId(null);
		it.setOrderPoints(getOrderPoints());
		it.setPrice(getPrice());
		it.setUnits(getUnits());
		return it;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}
